#include "queue.h"
#include <assert.h>

void queue_init(queue_node * queue)
{
    queue->len = 0;
    list_init(&queue->entries);
}

void enqueue(queue_node * queue, struct entry * entry)
{
    list_tailadd(&queue->entries, &entry->node);
    queue->len++;
}

struct entry * dequeue(queue_node * queue)
{
    assert(queue->len - 1 >= 0);

    struct entry * res = LIST_ENTRY(queue->entries.next, struct entry);
    list_del(queue->entries.next);
    queue->len--;

    return res;
}
